package com.trace.app.controller;


import com.trace.app.entity.ResponseResult;
import com.trace.app.entity.Supplier;
import com.trace.app.service.SupplierService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Supplier)表控制层
 *
 * @author lionkliu
 * @since 2024-04-28 18:29:31
 */
@RestController
@RequestMapping("supplier")
public class SupplierController {

    @Resource
    private SupplierService supplierService;

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return supplierService.selectPage(pageNum, pageSize);
    }

    @GetMapping("/search")
    public ResponseResult search(@RequestParam("pageNum") Integer pageNum,
                                 @RequestParam("pageSize") Integer pageSize,
                                 @RequestParam(value = "name") String name) {
        return supplierService.search(pageNum, pageSize, name);
    }

    @GetMapping("/getLabelValue")
    public ResponseResult getLabelValue() {
        return supplierService.getLabelValue();
    }

    @GetMapping("/list")
    public ResponseResult list() {
        return ResponseResult.okResult(supplierService.list());
    }

    @GetMapping("{id}")
    public ResponseResult selectOne(@PathVariable Integer id) {
        return supplierService.selectOne(id);
    }

    @PostMapping
    public ResponseResult insert(@RequestBody Supplier supplier) {
        return supplierService.insertOne(supplier);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Supplier supplier) {
        return supplierService.updateOne(supplier);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return supplierService.deleteById(id);
    }

}
